<template>
  <view :style="themeColor">
    <view class="page">
      <view class="flex benben-position-layout flex flex-wrap align-center addSchool_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center justify-between flex-sub addSchool_fd0_0'>
          <view class='flex flex-wrap align-center addSchool_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="switchTab"
            data-url="/pages/tabBar/myPosts/myPosts">
            <text class='fu-iconfont2  addSchool_fd0_0_c0_c0'>&#xE794;</text>
          </view>
          <view class='flex flex-wrap align-stretch justify-center'>
            <text class='addSchool_fd0_0_c1_c0'>添加学校</text>
          </view>
          <view class='flex flex-wrap align-center justify-end addSchool_fd0_0_c0'>

            <text v-if="into" @click.stop="goHOme">跳过</text>
          </view>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
      <view class="padding-sm topdesc">
        如需更改学校验证信息，请联系我们！
      </view>
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout addSchool_flex_1">
        <view class='flex flex-direction flex-wrap align-stretch addSchool_fd1_0'>
          <text class='addSchool_fd1_0_c0'>学校</text>
          <view class='flex flex-wrap align-center justify-between addSchool_fd1_0_c1' @tap.stop="handleJumpDiy"
            data-type="navigateTo" :data-url="`/pages/dlzc/choiceSchool/choiceSchool`">
            <benben-input class='flex-sub addSchool_fd1_0_c1_c0' type="text" :placeholder="`请选择`" confirm-type="done"
              :maxlength="-1" :disabled='true' placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx"
              v-model="operateschool_id.school_name" />
            <image class='addSchool_fd1_0_c1_c1' mode="aspectFit" :src='STATIC_URL+"53.png"'></image>
          </view>
        </view>
        <view class='flex flex-direction flex-wrap align-stretch addSchool_fd1_0'>
          <text class='addSchool_fd1_0_c0'>专业</text>
          <view class='flex flex-wrap align-center justify-between addSchool_fd1_0_c1'>
            <benben-input class='flex-sub addSchool_fd1_0_c1_c0' type="text" :placeholder="`请输入`" confirm-type="done"
              :maxlength="-1" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" v-model="model" />
          </view>
        </view>
        <view class='flex flex-direction flex-wrap align-stretch addSchool_fd1_0'>
          <text class='addSchool_fd1_0_c0'>时间</text>
          <view class='flex flex-wrap align-center justify-between'>
            <view class='flex flex-wrap align-center justify-between addSchool_fd1_0_c1'
              @tap.stop="pickerDiy1703928048452=true">
              <benben-input class='flex-sub addSchool_fd1_2_c1_c0_c0' type="text" :placeholder="`入学时间`"
                confirm-type="done" v-model="bagin_time" :maxlength=" -1" :disabled='true'
                placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" />
              <image class='addSchool_fd1_0_c1_c1' mode="aspectFit" :src='STATIC_URL+"53.png"'></image>
            </view>
            <text class='addSchool_fd1_2_c1_c1'>-</text>
            <view class='flex flex-wrap align-center justify-between addSchool_fd1_0_c1'
              @tap.stop="pickerDiy1703927784282=true">
              <benben-input class='flex-sub addSchool_fd1_2_c1_c0_c0' type="text" :placeholder="`毕业时间`"
                v-model="over_time" confirm-type="done" :maxlength="-1" :disabled='true'
                placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" />
              <image class='addSchool_fd1_0_c1_c1' mode="aspectFit" :src='STATIC_URL+"53.png"'></image>
            </view>
          </view>
        </view>
        <view class='flex flex-direction flex-wrap align-stretch addSchool_fd1_0' v-if="is_school!=2">
          <text class='addSchool_fd1_0_c0'>邮箱号<text
              class="text-red margin-left-sm text-sm text-weight-700">(非必填,可后续完善)</text></text>
          <view class='flex flex-wrap align-center justify-between addSchool_fd1_0_c1'>
            <benben-input class='flex-sub addSchool_fd1_0_c1_c0' type="text" :placeholder="`请输入`" confirm-type="done"
              :maxlength="-1" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" v-model="mailbox" />
            <!-- <image class='addSchool_fd1_0_c1_c1' mode="aspectFit" :src='STATIC_URL+"53.png"'></image> -->
          </view>
          <text class='addSchool_fd1_3_c2'>提示：请用{{operateschool_id.email_end}}邮箱验证学生身份</text>
        </view>
        <view class='flex flex-direction flex-wrap align-stretch addSchool_fd1_0' v-if="is_school!=2">
          <text class='addSchool_fd1_0_c0'>邮箱验证码</text>
          <view class='flex flex-wrap align-center justify-between addSchool_fd1_0_c1'>
            <benben-input class='flex-sub addSchool_fd1_0_c1_c0' type="number" :placeholder="`请输入`" confirm-type="done"
              :maxlength="4" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" v-model="code" />

            <benben-send-verification-code key='1703922989612' ref="vCode1703922989612" class=' addSchool_fd1_4_c1_c1'
              after-text='后重新获取' before-text='获取验证码' emptye-text='请输入邮箱号' validate-text='请输入正确的邮箱号' account-type='email'
              :operateschoolid="operateschool_id.email_end" account-into='test' :auto='true' type='5'
              :phone="mailbox"></benben-send-verification-code>
          </view>
        </view>
        <view class='flex flex-wrap align-center justify-center addSchool_fd1_5' v-if="is_school!=2">
          <button class='addSchool_fd1_5_c0' @tap.stop="bindingSchoolsFunc()">确定</button>
        </view>
      </view>

      <!---flex布局flex布局结束-->
      <!--入学时间开始 -->
      <benben-picker ref="benbenWritePickerCodepicker2" :visible.sync="pickerDiy1703928048452" mode='date'
        :mask-show='true' :timeout='true' :picker-height='88' :current='true' fields='year' start-year='1900'
        :value.sync='bagin_time' :end-year='endyear' from-data=''>
        <template #picker-header>
          <view class='flex flex-wrap align-center justify-between addSchool_picker2_0'>
            <text class='addSchool_picker2_0_c0' @tap="$refs.benbenWritePickerCodepicker2.cancel()">取消</text>
            <text>选择时间</text>
            <text class='addSchool_picker2_0_c2' @tap="$refs.benbenWritePickerCodepicker2.pickerConfirm()">确认</text>
          </view>
        </template>
      </benben-picker>
      <!--入学时间结束 -->
      <!--毕业时间开始 -->
      <benben-picker ref="benbenWritePickerCodepicker3" :visible.sync="pickerDiy1703927784282" mode='date'
        :picker-height='88' :current='true' :mask-show='true' fields='year' :timeout='true' :start-year='bagin_time'
        :value.sync='over_time' end-year='2050-12-31' from-data=''>
        <template #picker-header>
          <view class='flex flex-wrap align-center justify-between addSchool_picker3_0'>
            <text class='addSchool_picker3_0_c0' @tap="$refs.benbenWritePickerCodepicker3.cancel()">取消</text>
            <text>选择时间</text>
            <text class='addSchool_picker3_0_c2' @tap="$refs.benbenWritePickerCodepicker3.pickerConfirm()">确认</text>
          </view>
        </template>
      </benben-picker>
      <!--毕业时间结束 -->


    </view>
  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js'

  export default {
    components: {},


    data() {
      return {
        "pickerDiy1703927784282": false,
        "pickerDiy1703928048452": false,
        "model": "",
        "apply_time": "",
        "mailbox": "",
        "operateschool_id": {
          "aid": "",
          "school_name": "",
          email_end: ''
        },
        "code": "",
        "bagin_time": "",
        "over_time": "",
        "aid": "",
        is_school: 0,
        endyear: new Date().getFullYear()
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },

    },
    watch: {},
    onLoad(options) {
      let {
        aid,
        into
      } = options
      if (aid !== undefined) this.aid = aid
      if (into !== undefined) this.into = into
      this.endyear = (this.endyear + 1).toString()
      console.log('endyeendyearendyearendyearar', this.endyear)
      this.getDaraFunc()
      this.diyPageListen()
    },
    onUnload() {
      this.diyOffPageListen()
    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      goHOme() {
        if (!validate(this.operateschool_id.aid, 'require')) {
          uni.switchTab({
            url: `/pages/tabBar/homePage/homePage`
          })
          return false;
        }
        this.$api.post(global.apiUrls.post6576c9f9a2e32, {
          aid: this.aid,
          model: this.model,
          apply_time: this.apply_time,
          mailbox: this.mailbox,
          operateschool_id: this.operateschool_id.aid,
          code: this.code
        }).then(res => {
          if (res.data.code == 1) {
            uni.switchTab({
              url: `/pages/tabBar/homePage/homePage`
            })
          } else {
            this.$message.info(res.data.msg)
          }
        })

      },
      async getDaraFunc() {
        //请求方法
        //数据验证

        let datadataInfo = await this.$api.get(global.apiUrls.post5c78c4772da97, {

        });

        if (datadataInfo.data.code != 1) {
          this.$message.info(datadataInfo.data.msg);
          return
        }
        let infodataInfo = datadataInfo.data.data;
        this.model = infodataInfo.school_info.model
        this.operateschool_id.aid = infodataInfo.school_info.operateschool_id
        this.operateschool_id.school_name = infodataInfo.school_info.school_name
        this.operateschool_id.email_end = infodataInfo.school_info.email_end
        this.mailbox = infodataInfo.school_info.mailbox
        this.is_school = infodataInfo.is_school
        if (infodataInfo.school_info.apply_time) {
          let arrs = infodataInfo.school_info.apply_time.split('-')
          this.bagin_time = arrs[0]
          this.over_time = arrs[1]
        }
      },

      //绑定学校
      async bindingSchoolsFunc() {

        if (!validate(this.operateschool_id.aid, 'require')) {
          this.$message.info('请选择学校');
          return false;
        }
        if (!validate(this.model, 'require')) {
          this.$message.info('专业不能为空');
          return false;
        }
        if (!validate(this.bagin_time, 'require')) {
          this.$message.info('请选择入学时间');
          return false;
        }
        if (!validate(this.over_time, 'require')) {
          this.$message.info('请选择毕业时间');
          return false;
        }

        if (this.mailbox) {
          let v = this.operateschool_id.email_end
          // return /^[0-9a-zA-Z_.-]+[@][0-9a-zA-Z_.-]+([.][a-zA-Z]+){1,2}$/.test(value);
          let reg = new RegExp("[0-9a-zA-Z_.-]+[@]" + v + "$");
          console.log('kkkk', reg.test(this.mailbox), reg);
          if (!reg.test(this.mailbox)) {
            this.$message.info('填写正确的学校邮箱');
            return false;
          }
          // if (!validate(this.mailbox, 'email')) {
          //   this.$message.info('请输入正确的邮箱号');
          //   return false;
          // }
        }

        // return;

        // if (!validate(this.code, 'require')) {
        //   this.$message.info('验证码不能为空');
        //   return false;
        // }
        // if (!validate(this.code, 'captcha')) {
        //   this.$message.info('请输入正确的验证码');
        //   return false;
        // }
        //请求方法
        //数据验证
        this.apply_time = this.bagin_time + '-' + this.over_time
        let data6576c9f9a2e32 = await this.$api.post(global.apiUrls.post6576c9f9a2e32, {
          aid: this.aid,
          model: this.model,
          apply_time: this.apply_time,
          mailbox: this.mailbox,
          operateschool_id: this.operateschool_id.aid,
          code: this.code
        });

        if (data6576c9f9a2e32.data.code != 1) {
          this.$message.info(data6576c9f9a2e32.data.msg);
          return
        }
        setTimeout(() => {
          if (this.aid) {
            uni.navigateBack()
          } else {
            uni.switchTab({
              url: `/pages/tabBar/homePage/homePage`
            })
          }
          // this.toLoginDiy();

        }, 500)
      },
      //页面监听
      diyPageListen() {
        uni.$on('thSchool', (data) => {
          console.log('is_school', this.operateschool_id, data)
          if (this.operateschool_id.aid != data.aid) {
            this.is_school = 0
          }
          this.operateschool_id = data;
        });
      },
      //注销页面监听
      diyOffPageListen() {
        uni.$off('thSchool');
      }
    }
  };
</script>
<style lang="scss" scoped>
  .topdesc {
    color: rgb(100, 80, 235);
    background-color: rgba(100, 80, 235, 0.1)
  }

  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: rgba(255, 255, 255, 1);
    background-size: 100% auto;
  }

  .addSchool_flex_0 {
    border-bottom: 1px solid #eee;
    background: #fff;
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .addSchool_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 700;
    color: #333333;
    line-height: 50rpx;
  }

  .addSchool_fd0_0_c0_c0 {
    font-size: 36rpx;
    color: #333;
  }

  .addSchool_fd0_0_c0 {
    width: 120rpx;
  }

  .addSchool_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .addSchool_flex_1 {
    padding: 32rpx 32rpx 0rpx 32rpx;
  }

  .addSchool_fd1_5_c0 {
    background: rgba(100, 80, 235, 1);
    border-radius: 44rpx;
    width: 686rpx;
    line-height: 88rpx;
    font-size: 32rpx;
    color: #fff;
  }

  .addSchool_fd1_5 {
    margin: 128rpx 0rpx 0rpx 0rpx;
  }

  .addSchool_fd1_4_c1_c1 {
    line-height: 42rpx;
    text-align: center;
    font-size: 28rpx;
    color: rgba(51, 51, 51, 1);
  }

  .addSchool_fd1_3_c2 {
    color: #FF892E;
    font-size: 22rpx;
    font-weight: 400;
    line-height: 32rpx;
    margin: 16rpx 0rpx 0rpx 0rpx;
  }

  .addSchool_fd1_2_c1_c1 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 400;
    line-height: 32rpx;
  }

  .addSchool_fd1_2_c1_c0_c0 {
    color: rgba(51, 51, 51, 1);
    font-size: 32rpx;
    width: 250rpx;
  }

  .addSchool_fd1_0_c1_c1 {
    width: 14rpx;
    height: 26rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .addSchool_fd1_0_c1_c0 {
    color: rgba(51, 51, 51, 1);
    font-size: 32rpx;
  }

  .addSchool_fd1_0_c1 {
    background: rgba(248, 248, 248, 1);
    margin: 16rpx 0rpx 0rpx 0rpx;
    border-radius: 12rpx;
    background-size: 100% auto;
    padding: 22rpx 24rpx 22rpx 24rpx;
  }

  .addSchool_fd1_0_c0 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 32rpx;
  }

  .addSchool_fd1_0 {
    margin: 0rpx 0rpx 32rpx 0rpx;
  }

  .addSchool_picker2_0_c2 {
    color: rgba(100, 80, 235, 1);
  }

  .addSchool_picker2_0_c0 {
    color: var(--benbenFontColor2);
  }

  .addSchool_picker2_0 {
    border-bottom: 1px solid #eee;
    background: #fff;
    padding: 0rpx 32rpx 0rpx 32rpx;
    line-height: 88rpx;
    border-radius: 25rpx 25rpx 0rpx 0rpx;
    background-size: 100% auto !important;
  }

  .addSchool_picker3_0_c2 {
    color: rgba(100, 80, 235, 1);
  }

  .addSchool_picker3_0_c0 {
    color: var(--benbenFontColor2);
  }

  .addSchool_picker3_0 {
    border-bottom: 1px solid #eee;
    background: #fff;
    padding: 0rpx 32rpx 0rpx 32rpx;
    line-height: 88rpx;
    border-radius: 25rpx 25rpx 0rpx 0rpx;
    background-size: 100% auto !important;
  }
</style>
